package com.guodi.model.entity;

import lombok.Getter;
import lombok.Setter;
import java.util.List;

@Getter
@Setter
public class Node {

    private String id;
    private String name;
    private String path;
    //1:目录 2:文件
    private Integer type;
    private Integer treeLevel;
    private String parentId;

    private List<Node> children;
    private Node() {}

    private Node(String id, String name, String path, Integer type, Integer treeLevel, String parentId) {
        this.id = id;
        this.name = name;
        this.path = path;
        this.type = type;
        this.treeLevel = treeLevel;
        this.parentId = parentId;
    }

    public static Node getDirNode(String id, String name, String path, String parentId) {
        return new Node(id, name, path, 1, getTreeLevel(path),parentId);
    }
    public static Node getFileNode(String id, String name, String path, String parentId) {
        return new Node(id, name, path, 2, getTreeLevel(path),parentId);
    }

    public static Integer getTreeLevel(String path){
        char[] chars = path.toCharArray();
        int level = 0;
        for(int i = 0; i < chars.length; i++){
            if(chars[i] == '/'){
                level++;
            }
        }
        return level;
    }
}
